<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Control</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Control</h1>

<p>Makes a variety of changes to a control.</p>

<pre class="Syntax">Control, Cmd [, Value, Control, WinTitle, WinText, ExcludeTitle, ExcludeText]</pre>
<h3>Parameters</h3>
<dl>

  <dt>Cmd, Value</dt>
  <dd><p>See list below.</p></dd>

  <dt>Control</dt>
  <dd><p>Can be either ClassNN (the classname and instance number of the control) or the control's text, both of which can be determined via Window Spy. When using text, the matching behavior is determined by <a href="SetTitleMatchMode.htm">SetTitleMatchMode</a>. If this parameter is blank, the target window's topmost control will be used.</p>
    <p>To operate upon a control's HWND (window handle), leave the <em>Control</em> parameter blank and specify <code>ahk_id %ControlHwnd%</code> for the <em>WinTitle</em> parameter (this also works on hidden controls even when <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> is Off). The HWND of a control is typically retrieved via <a href="ControlGet.htm#Hwnd">ControlGet Hwnd</a>, <a href="MouseGetPos.htm">MouseGetPos</a>, or <a href="DllCall.htm">DllCall</a>.</p></dd>

  <dt>WinTitle</dt>
  <dd><p>A window title or other criteria identifying the target window. See <a href="../misc/WinTitle.htm">WinTitle</a>.</p></dd>

  <dt>WinText</dt>
  <dd><p>If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if <a href="DetectHiddenText.htm">DetectHiddenText</a> is ON.</p></dd>

  <dt>ExcludeTitle</dt>
  <dd><p>Windows whose titles include this value will not be considered.</p></dd>

  <dt>ExcludeText</dt>
  <dd><p>Windows whose text include this value will not be considered.</p></dd>

</dl>

<h3>Cmd, Value</h3>
<p>The <em>Cmd</em> and <em>Value</em> parameters are dependent upon each other and their usage is described below.</p>
<p><strong>Check</strong>: Turns on (checks) a radio button or checkbox.</p>
<p><strong>Uncheck</strong>: Turns off a radio button or checkbox.</p>
<p><strong>Enable</strong>: Enables a control if it was previously disabled.</p>
<p><strong>Disable</strong>: Disables or &quot;grays out&quot; a control.</p>
<p><strong>Show</strong>: Shows a control if it was previously hidden.</p>
<p><strong>Hide</strong>: Hides a control. If you additionally want to prevent a control's shortcut key (underlined letter) from working, disable the control via <code>Control Disable</code>.</p>
<p><strong>Style, N</strong> <u>or</u> <strong>ExStyle, N</strong>: Changes the style or extended style of a control, respectively. If the first character of <strong>N</strong> is a plus or minus sign, the style(s) in <strong>N</strong> are added or removed, respectively. If the first character is a caret (^), the style(s) in N are each toggled to the opposite state. If the first character is a digit, the control's style is overwritten completely; that is, it becomes <strong>N</strong>. <a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if the target window/control is not found or the style is not allowed to be applied.</p>
<p>Certain style changes require that the entire window be redrawn using <a href="WinSet.htm">WinSet Redraw</a>. Also, the <a href="../misc/Styles.htm">styles table</a> lists some of the style numbers. For example:</p>
<pre>Control, Style, ^0x800000, Edit1, WinTitle  <em>; Set the WS_BORDER style to its opposite state.</em></pre>
<p><strong>ShowDropDown</strong>: Drops a ComboBox so that its choices become visible.</p>
<p><strong>HideDropDown</strong>: Reverses the above.</p>
<p><strong>TabLeft [, Count]</strong> and <strong>TabRight [, Count]</strong>: Moves left or right by one or more tabs in a SysTabControl32. <em>Count</em> is assumed to be 1 if omitted or blank. To instead select a tab directly by number, replace the number 5 below with one less than the tab number you wish to select. In other words, 0 selects the first tab, 1 selects the second, and so on:</p>
<pre><a href="PostMessage.htm">SendMessage</a>, 0x1330, <span class="red">5</span>,, SysTabControl321, WinTitle  <em>; 0x1330 is TCM_SETCURFOCUS.</em>
Sleep 0  <em>; This line and the next are necessary only for certain tab controls.</em>
SendMessage, 0x130C, <span class="red">5</span>,, SysTabControl321, WinTitle  <em>; 0x130C is TCM_SETCURSEL.</em></pre>
<p><strong>Add, String</strong>: Adds <em>String</em> as a new entry at the bottom of a ListBox, ComboBox (and possibly other types).</p>
<p><strong>Delete, N</strong>: Deletes the Nth entry from a ListBox or ComboBox. <em>N</em> should be 1 for the first entry, 2 for the second, etc.</p>
<p><strong>Choose, N</strong>: Sets the selection in a ListBox or ComboBox to be the Nth entry. <em>N</em> should be 1 for the first entry, 2 for the second, etc. To select or deselect all items in a <em>multi-select</em> listbox, follow these examples:</p>
<pre><a href="PostMessage.htm">PostMessage</a>, 0x185, 1, -1, ListBox1, WinTitle  <em>; Select all listbox items. 0x185 is LB_SETSEL.</em></pre>
<p><strong>ChooseString, String</strong>: Sets the selection (choice) in a ListBox or ComboBox to be the first entry whose leading part matches <em>String</em>. The search is not case sensitive. For example, if a ListBox/ComboBox contains the item &quot;UNIX Text&quot;, specifying the word unix (lowercase) would be enough to select it.</p>
<p><strong>EditPaste, String</strong>: Pastes <em>String</em> at the caret/insert position in an Edit control (this does not affect the contents of the <a href="../misc/Clipboard.htm">clipboard</a>).</p>
<h3>ErrorLevel</h3>
<p><span class="ver">[v1.1.04+]</span> This command is able to throw an exception on failure. For more information, see <a href="Catch.htm#RuntimeErrors">Runtime Errors</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise.</p>
<h3>Remarks</h3>
<p>To improve reliability, a delay is done automatically after every use of this command (except for <em>Style</em> and <em>ExStyle</em>). That delay can be changed via <a href="SetControlDelay.htm">SetControlDelay</a>.</p>
<p>To discover the ClassNN or HWND of the control that the mouse is currently hovering over, use <a href="MouseGetPos.htm">MouseGetPos</a>.</p>
<p>Window titles and text are case sensitive. Hidden windows are not detected unless <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> has been turned on.</p>

<h3>Related</h3>
<p><a href="SetControlDelay.htm">SetControlDelay</a>, <a href="ControlGet.htm">ControlGet</a>, <a href="GuiControl.htm">GuiControl</a>, <a href="ControlGetText.htm">ControlGetText</a>, <a href="ControlSetText.htm">ControlSetText</a>, <a href="ControlMove.htm">ControlMove</a>, <a href="ControlGetPos.htm">ControlGetPos</a>, <a href="ControlClick.htm">ControlClick</a>, <a href="ControlFocus.htm">ControlFocus</a>, <a href="ControlSend.htm">ControlSend</a>, <a href="WinSet.htm">WinSet</a></p>
<h3>Example</h3>
<pre class="NoIndent">Control, HideDropDown, , ComboBox1, Some Window Title</pre>

</body>
</html>
